﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Diagnostics.Tracing;


namespace Toom.CellularAutomata.Debug
{


	public class CADebugger
	{

		public enum DebugMessageSource
		{
			Default = 0,
			Painting,
			Drawing,
			Perf,
			FieldChunks,

			// and finally
			Unknown = -1
		}
	
		// ctor?


		public static void DebugPrintLine( DebugMessageSource? src, string s )
		{
			System.Diagnostics.Trace.WriteLine( s, src.ToString() );
			System.Diagnostics.Trace.Flush();
		}



		public static List<DebugMessageSource> GetAllMessageSource()
		{
			List<DebugMessageSource> list = new List<DebugMessageSource>();
			list.Add( DebugMessageSource.Default );
			list.Add( DebugMessageSource.FieldChunks );
			list.Add( DebugMessageSource.Painting );
			list.Add( DebugMessageSource.Drawing );
			list.Add( DebugMessageSource.Perf );
			list.Add( DebugMessageSource.Unknown );
			return list;
		}


	}//class CADebugger


	public interface ICATraceReceiver
	{
		void ReceiveTraceMessage( string message );
		void ReceiveTraceMessage( string message, string category );
	}


	//[ConfigurationElementType(typeof(CustomTraceListenerData))]
	public class CATraceListener : TraceListener
	{
		// CTOR
		public CATraceListener( ICATraceReceiver myReceiver )
		{
			this.myReceiver = myReceiver;
			//messageQueue = new Queue<string>();

		}

		// DATA
		public ICATraceReceiver myReceiver;
		//public Queue<string> messageQueue;


		//public override void Write( string message )
		//{
		//	//messageQueue.Enqueue( message );
		//	myReceiver.ReceiveTraceMessage( message );
		//}

		public override void WriteLine( string message, string category )
		{
			//messageQueue.Enqueue( message );
			myReceiver.ReceiveTraceMessage( message, category );
		}

		public override void Write( string message )
		{
			//messageQueue.Enqueue( message );
			myReceiver.ReceiveTraceMessage( message );
		}


		public override void WriteLine( string message )
		{
			//messageQueue.Enqueue( message );
			myReceiver.ReceiveTraceMessage( message );
		}


	}//class CATraceListener

}//ns
